<template>
  <div>
    <!-- current-page当前页数 -->
    <el-table :data="userlist" border style="width: 100%">
      <el-table-column prop="uid" label="用户编号" width="180">
      </el-table-column>
      <el-table-column prop="username" label="用户名称" width="180">
      </el-table-column>
      <el-table-column prop="rolename" label="所属角色"> </el-table-column>
      <el-table-column prop="status" label="状态"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="item">
          <div>
            <el-button
              class="btnInfo"
              type="primary"
              icon="el-icon-edit"
              size="mini"
              circle
              @click="edit(item.row.uid)"
            ></el-button>
            <el-button
              class="btnInfo"
              type="danger"
              icon="el-icon-delete"
              size="mini"
              circle
              @click="del(item.row.uid)"
            ></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="userCont"
      :page-size="userSize"
      @current-change="changePage"
      :current-page="userPage"
    >
    </el-pagination>
  </div>
</template>

<script>
import { mapGetters, mapActions } from "vuex";
import {userDelete} from '../../request/api'
export default {
  data() {
    return {};
  },

  computed: {
    ...mapGetters({
      userlist: "user/getusers",
      userCont: "user/getCont",
      userSize: "user/getSize",
      userPage: "user/getPage",
    }),
  },
  mounted() {
    this.getContActions();
    console.log(this.userlist);
    if (this.userlist.length == 0||[]) {
      this.getUsers();
    }
  },
  methods: {
    // 点击页码切换
    changePage(n) {
      console.log(n, "当前页");
      this.getPage(n);
      this.getUsers();
    },
    ...mapActions({
      getUsers: "user/getUserList",
      getContActions: "user/getContActions",
      getPage: "user/getUserPage",
    }),
    // 删除
    del(uid) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          userDelete({ uid: uid }).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.getUsers();
              this.getContActions();
            } else {
              this.$message.error(res.msg);
            }
          });
        })
        .catch(() => {
          
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //点击编辑按钮事件
    edit(uid) {
      this.$emit("edit", uid);
    },
  },
};
</script>

<style  scoped>
</style>
